#ifndef __FLOW_MODULE_H__
#define __FLOW_MODULE_H__

#include "common.h"
#include "global_config.h"

/* Flow sensor channels */
#define FLOW_CHANNELS 2

/* TIM2 input capture configuration */
#define FLOW_TIMER_TIM2
#define FLOW_CH1_PIN GET_PIN(A, 0)  /* TIM2_CH1 */
#define FLOW_CH2_PIN GET_PIN(A, 1)  /* TIM2_CH2 */

/* Flow message types */
typedef enum {
    FLOW_MSG_DATA_READY = 1,
    FLOW_MSG_CALIBRATION,
    FLOW_MSG_RESET_TOTAL
} flow_msg_type_t;

/* Flow measurement structure */
typedef struct {
    uint32_t pulse_count;
    uint32_t last_pulse_count;
    float flow_rate;        /* L/min */
    float total_flow;       /* L */
    uint32_t last_calc_time;
} flow_data_t;

/* Function declarations */
rt_err_t flow_module_init(void);
void flow_thread_entry(void *parameter);
float flow_get_flow_rate(uint8_t channel);
float flow_get_total_flow(uint8_t channel);
rt_err_t flow_reset_total_flow(uint8_t channel);
rt_err_t flow_set_calibration(uint8_t channel, float pulse_constant, float k_factor);

/* External configuration access */
extern flow_config_t *flow_get_config(void);

#endif /* __FLOW_MODULE_H__ */